<?php

namespace App\Exceptions;

use Exception;

class BusinessException extends Exception
{
    protected $statusCode = 400;

    public function __construct(string $message = '', int $code = 0, int $statusCode = 400, \Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);
        $this->statusCode = $statusCode;
    }

    public function getStatusCode(): int
    {
        return $this->statusCode;
    }

    public static function stockInsufficient(string $message = '库存不足'): self
    {
        return new self($message, 1001, 400);
    }

    public static function orderNotFound(string $message = '订单不存在'): self
    {
        return new self($message, 1002, 404);
    }

    public static function orderCannotCancel(string $message = '订单无法取消'): self
    {
        return new self($message, 1003, 400);
    }

    public static function afterSalesNotFound(string $message = '售后申请不存在'): self
    {
        return new self($message, 1004, 404);
    }

    public static function afterSalesCannotCancel(string $message = '售后申请无法取消'): self
    {
        return new self($message, 1005, 400);
    }

    public static function unauthorized(string $message = '无权限操作'): self
    {
        return new self($message, 1006, 403);
    }

    public static function invalidOperation(string $message = '操作无效'): self
    {
        return new self($message, 1007, 400);
    }
}
